require("../../../utils/api.js");

var a = require("../../../utils/disapi.js"), t = getApp();

Page({
    data: {
        status: -2,
        item: {
            status: "待付款"
        },
        list: [],
        openid: "",
        money: 0,
        used_money: 0,
        cash_money: 0,
        commission: [],
        page: 1,
        last: 0
    },
    onLoad: function(e) {
        var o = t.globalData.openid;
        this.setData({
            openid: o
        });
        var s = this;
        wx.showLoading({
            title: "加载中"
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), a.get_dis_chil_order({
            openid: this.data.openid
        }).then(function(a) {
            if (0 == a.errno) {
                var t = a.data;
                if (0 == t.code) {
                    var e = t.data;
                    console.log(e);
                    var o = 0;
                    t.data.length < 20 && t.data.length > 0 && (o = 1), s.setData({
                        list: e,
                        last: o
                    });
                }
            }
            wx.hideLoading();
        }), a.get_dis_user_info({
            openid: this.data.openid
        }).then(function(a) {
            var t = a.data;
            0 == t.code && s.setData({
                used_money: parseFloat(t.data.used_mondey),
                money: parseFloat(t.data.money),
                cash_money: parseFloat(t.data.cash_money)
            });
        });
        a.get_dis_commission({}).then(function(a) {
            if (0 == a.errno) {
                var t = a.data;
                s.setData({
                    commission: t.data
                });
            }
        });
    },
    myTab: function(t) {
        var e = this, o = t.currentTarget.dataset.status;
        wx.showLoading({
            title: "加载中"
        }), console.log(o), a.get_dis_chil_order({
            openid: this.data.openid,
            state: o
        }).then(function(a) {
            if (0 == a.errno) {
                var t = a.data;
                if (0 == t.code) {
                    var o = 0;
                    t.data.length < 20 && (o = 1), e.setData({
                        list: t.data,
                        last: o
                    }), console.log(e.data.list);
                }
            }
            wx.hideLoading();
        }), this.setData({
            status: o
        });
    },
    onReachBottom: function(t) {
        var e = this, o = e.data.page + 1, s = e.data.status, i = e.data.list;
        a.get_dis_chil_order({
            openid: this.data.openid,
            state: s,
            page: o
        }).then(function(a) {
            if (console.log(a), 0 == a.errno) {
                for (var t = a.data, s = 1; s < t.data.length; s++) i.push(t.data[s]);
                if (0 == t.code) {
                    var n = 0;
                    t.data.length < 20 && (n = 1), e.setData({
                        list: i,
                        page: o,
                        last: n
                    }), console.log(e.data.list);
                }
            }
        });
    }
});